package org.yys.seata.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.yys.seata.entity.StorageEntity;
import org.yys.seata.service.StorageService;
import org.yys.seata.mapper.StorageMapper;
import org.springframework.stereotype.Service;

/**
* @author A
* @description 针对表【t_storage】的数据库操作Service实现
* @createDate 2023-12-05 16:05:19
*/
@Service
public class StorageServiceImpl extends ServiceImpl<StorageMapper, StorageEntity>
    implements StorageService{

    @Override
    public void descrease(Long productId, Integer count) {
        LambdaQueryWrapper<StorageEntity> eq = Wrappers.<StorageEntity>lambdaQuery().eq(StorageEntity::getProductId, productId);
        StorageEntity one = this.getOne(eq);
        if (one==null) {
            throw new RuntimeException("未找到商品");
        }
        one.setResidue(one.getResidue()-count);
        one.setUsed(one.getUsed()+count);

        this.updateById(one);
    }
}




